package com.codedancer.campus.client.api.lostFoundItemComment;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codedancer.campus.client.api.lostFoundItemComment.ro.LostFoundCommentPageSearchRo;
import com.codedancer.campus.client.api.lostFoundItemComment.ro.LostFoundItemCommentAddRo;
import com.codedancer.campus.client.service.ILostFoundItemCommentService;
import com.codedancer.campus.client.service.bo.lostFoundItemComment.LostFoundCommentPageSearchBo;
import com.codedancer.campus.client.service.bo.lostFoundItemComment.LostFoundItemCommentAddBo;
import com.codedancer.campus.client.service.vo.lostFoundItemComment.LostFoundItemCommentVo;
import com.codedancer.campus.common.core.BaseApi;
import com.codedancer.campus.common.response.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/lost-found-item-comment")
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,
    RequestMethod.PUT}, maxAge = 3600)
@Api(value = "失物招领物品评论Api", description = "失物招领物品评论Api", tags = "失物招领物品评论Api")
public class LostFoundItemCommentApi extends BaseApi {

    @Autowired
    private ILostFoundItemCommentService lostFoundItemCommentService;

    @PostMapping("/add")
    @ApiOperation("添加评论")
    public ApiResponse<String> add(@RequestBody @Valid @ApiParam(value = "评论添加Ro", required = true)
        LostFoundItemCommentAddRo lostFoundItemCommentAddRo) {
        LostFoundItemCommentAddBo lostFoundItemCommentAddBo = BeanUtil.copyProperties(
            lostFoundItemCommentAddRo, LostFoundItemCommentAddBo.class);
        lostFoundItemCommentAddBo.setCurrentUserUuid(currentLoginUuid());
        return success(lostFoundItemCommentService.add(lostFoundItemCommentAddBo));
    }

    @GetMapping("/page/{lostFoundItemUuid}")
    @ApiOperation("分页查询某个物品的评论")
    public ApiResponse<IPage<LostFoundItemCommentVo>> page(
        @PathVariable(value = "lostFoundItemUuid", required = true) @ApiParam(value = "物品uuid", required = true) String lostFoundItemUuid,
        @ApiParam(value = "物品分页搜索Ro", required = false) LostFoundCommentPageSearchRo lostFoundCommentPageSearchRo) {
        LostFoundCommentPageSearchBo lostFoundCommentPageSearchBo = BeanUtil.copyProperties(
            lostFoundCommentPageSearchRo, LostFoundCommentPageSearchBo.class);
        lostFoundCommentPageSearchBo.setLostFoundItemUuid(lostFoundItemUuid);
        return success(lostFoundItemCommentService.page(lostFoundCommentPageSearchBo));
    }
}
